package com.mall.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mall.common.utils.Response;
import com.mall.common.utils.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.mall.entity.Brand;
import com.mall.service.BrandService;
import com.mall.common.utils.PageUtils;
import com.mall.common.utils.R;



/**
 * 品牌
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-08-24 17:44:27
 */
@RestController
@RequestMapping("product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;



    /**
     * 列表
     */
    @PostMapping("/list")
    public Response list(@RequestBody Map<String, String> map){

        Integer currentPage = Integer.valueOf(map.get("page"));
        Integer pageSize = Integer.valueOf(map.get("limit"));
        String key = map.get("key");
        IPage<Brand> page = brandService.listPage(currentPage, pageSize, key);
        return new Response(ResponseMessage.SUCCESS).data(page);
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
        Brand brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("product:brand:save")
    public R save(@RequestBody Brand brand){
        brandService.save(brand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("product:brand:update")
    public R update(@RequestBody Brand brand){
        brandService.updateDetail(brand);
        brandService.updateById(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("product:brand:delete")
    public R delete(@RequestBody Long[] brandIds){
        brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }


    @GetMapping("/allbrand")
    public Response listall(){
        List<Brand> list = brandService.list();
        return new Response(ResponseMessage.SUCCESS).data(list);
    }
}
